# https://my.oschina.net/u/4589216/blog/4427748

import pytest
from Day72.example import plus

test_data = [{"num1": 3,
              "num2": 5,
              "num1+num2": 8,
              "id": "验证3+5=8"
              },
             {"num1": 2,
              "num2": 4,
              "num1+num2": 6,
              "id": "验证2+4=6"
              }
             ]

def pytest_generate_tests(metafunc):
    ids = []
    if "parameters" in metafunc.fixturenames:
        for data in test_data:  # 用test_data中的id作为测试用例名称
            ids.append(data['id'])
        metafunc.parametrize("parameters", test_data, ids=ids, scope="function")


def test_add(parameters):
    num1 = parameters["num1"]
    num2 = parameters["num2"]
    print(num1, num2)
    assert plus(num1, num2) == parameters['num1+num2']


if __name__ == '__main__':
    pytest.main(['-s', 'mengfeiyuan.py'])